
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/14/2013 19:37:08
-- Generated from EDMX file: C:\Users\MiS\Documents\Visual Studio 2010\Projects\KlubSportowy\KlubSportowy\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ATH];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ContributionsWhoPaid_Contributions]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContributionsWhoPaid] DROP CONSTRAINT [FK_ContributionsWhoPaid_Contributions];
GO
IF OBJECT_ID(N'[dbo].[FK_ContributionsWhoPaid_WhoPaid]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContributionsWhoPaid] DROP CONSTRAINT [FK_ContributionsWhoPaid_WhoPaid];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[ContributionsSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContributionsSet];
GO
IF OBJECT_ID(N'[dbo].[WhoPaidSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WhoPaidSet];
GO
IF OBJECT_ID(N'[dbo].[NewsSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[NewsSet];
GO
IF OBJECT_ID(N'[dbo].[ActivitiesSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ActivitiesSet];
GO
IF OBJECT_ID(N'[dbo].[CompetitionsSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CompetitionsSet];
GO
IF OBJECT_ID(N'[dbo].[CompetitionInRoleSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CompetitionInRoleSet];
GO
IF OBJECT_ID(N'[dbo].[ContributionsWhoPaid]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContributionsWhoPaid];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'ContributionsSet'
CREATE TABLE [dbo].[ContributionsSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Amount] decimal(18,0)  NOT NULL,
    [PaymentDate] datetime  NOT NULL,
    [ContributionDate] datetime  NOT NULL,
    [State] bit  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'WhoPaidSet'
CREATE TABLE [dbo].[WhoPaidSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Surname] nvarchar(max)  NOT NULL,
    [Amount] decimal(18,0)  NOT NULL,
    [Title] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'NewsSet'
CREATE TABLE [dbo].[NewsSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [RoleID] nvarchar(max)  NULL,
    [Date] datetime  NOT NULL,
    [Text] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ActivitiesSet'
CREATE TABLE [dbo].[ActivitiesSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] datetime  NOT NULL,
    [Date] datetime  NOT NULL
);
GO

-- Creating table 'CompetitionsSet'
CREATE TABLE [dbo].[CompetitionsSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Date] datetime  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'CompetitionInRoleSet'
CREATE TABLE [dbo].[CompetitionInRoleSet] (
    [CompetitionId] uniqueidentifier  NOT NULL,
    [RoleId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'ContributionsWhoPaid'
CREATE TABLE [dbo].[ContributionsWhoPaid] (
    [Contributions_Id] int  NOT NULL,
    [WhoPaid_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'ContributionsSet'
ALTER TABLE [dbo].[ContributionsSet]
ADD CONSTRAINT [PK_ContributionsSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'WhoPaidSet'
ALTER TABLE [dbo].[WhoPaidSet]
ADD CONSTRAINT [PK_WhoPaidSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'NewsSet'
ALTER TABLE [dbo].[NewsSet]
ADD CONSTRAINT [PK_NewsSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ActivitiesSet'
ALTER TABLE [dbo].[ActivitiesSet]
ADD CONSTRAINT [PK_ActivitiesSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CompetitionsSet'
ALTER TABLE [dbo].[CompetitionsSet]
ADD CONSTRAINT [PK_CompetitionsSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [CompetitionId], [RoleId] in table 'CompetitionInRoleSet'
ALTER TABLE [dbo].[CompetitionInRoleSet]
ADD CONSTRAINT [PK_CompetitionInRoleSet]
    PRIMARY KEY CLUSTERED ([CompetitionId], [RoleId] ASC);
GO

-- Creating primary key on [Contributions_Id], [WhoPaid_Id] in table 'ContributionsWhoPaid'
ALTER TABLE [dbo].[ContributionsWhoPaid]
ADD CONSTRAINT [PK_ContributionsWhoPaid]
    PRIMARY KEY NONCLUSTERED ([Contributions_Id], [WhoPaid_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Contributions_Id] in table 'ContributionsWhoPaid'
ALTER TABLE [dbo].[ContributionsWhoPaid]
ADD CONSTRAINT [FK_ContributionsWhoPaid_Contributions]
    FOREIGN KEY ([Contributions_Id])
    REFERENCES [dbo].[ContributionsSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [WhoPaid_Id] in table 'ContributionsWhoPaid'
ALTER TABLE [dbo].[ContributionsWhoPaid]
ADD CONSTRAINT [FK_ContributionsWhoPaid_WhoPaid]
    FOREIGN KEY ([WhoPaid_Id])
    REFERENCES [dbo].[WhoPaidSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContributionsWhoPaid_WhoPaid'
CREATE INDEX [IX_FK_ContributionsWhoPaid_WhoPaid]
ON [dbo].[ContributionsWhoPaid]
    ([WhoPaid_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------